import tornado.web
import tornado.ioloop
from . import utils
import json
'''
#
#7.2 场景分类
同步
    http://ip:port/pic/classify
    {
        "fileUrl":"",
        "id":"1"
    }

pet poultry architecture landscape botany flower common_bill other_bill
new_train_ticket old_train_ticket person crowd parade gun flag
porn1 porn2 porn3 porn4
bloodiness self_burning burned fire chat friend_circle expression
QR_code game packsack dishes food goods_shelf bus trunk vehicle_armored vehicle_small
vehicle_special vehicle_bike vehicle_trim
house_certificate residence_booklet driving_license
marriage_license old_marriage_license
identity_card bank_card YP_text WB_text NP_text shoe clothing other otherAnimal
'''
class PicClassify(tornado.web.RequestHandler):

    def post(self, *args, **kwargs):
        resp = None
        try:
            data=json.loads(self.request.body)
            print(data)
            paramerror = utils.checkParam(data,{
                "fileUrl":"",
                "id":"1"
            })
            if paramerror == '': #ok
                resp = {
                    "state":{
                        "ok":1,
                        "failed": ""
                    },
                    "result":[{
                            "name":"person",
                            "score":"0.84545"
                        },{
                            "name":"gun",
                            "score":"0.84545"
                        }
                    ],
                    "id":data['id']
                }
            else: #failed
                resp = {
                    "state":{
                        "ok":0,
                        "failed": paramerror
                    },
                    "result":[]
                }

        except BaseException as e:
            resp = {
                "state":{
                    "ok":0,
                    "failed": str(e)
                },
                "result":[]
            }

        self.write(resp)
